/**
 * YunLuActivityGroup.java
 * com.tc.yunlu.ui
 *
 * Function： TODO 
 *
 *   ver     date      		author
 * ──────────────────────────────────
 *   		 2012-4-9 		wangjieming
 *
 * Copyright (c) 2012, TNT All Rights Reserved.
 */

package com.jamin.tab;

import com.jamin.R;

import android.app.ActivityGroup;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.LinearLayout.LayoutParams;
import android.widget.LinearLayout;
import android.widget.RadioButton;

/**
 * ClassName:YunLuActivityGroup
 *
 * @author   wangjieming
 * @version  1.0
 * @since    v1.0
 * @Date	 2012-4-9 下午6:54:23 
 */
public class TabActivityGroup extends ActivityGroup implements OnCheckedChangeListener{

	private static final String TAG = "YunluActivityGroup=========wangjieming";
	private static final int FLAG_CONTACTS = 1;
	private static final int FLAG_LOCAL = 2;
	private static final int FLAG_NOTICE = 3;
	private static final int FLAG_SETTING = 4;
	LinearLayout subLayout = null;
	RadioButton mContactsRadio = null;
	RadioButton mLocalRadio = null;
	RadioButton mNoticeRadio = null;
	RadioButton mSettingRadio = null;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.yunlu_activity_group);
		initView();


	}

	private void initView() {
		subLayout = (LinearLayout) findViewById(R.id.main_view);
		mContactsRadio = (RadioButton) findViewById(R.id.main_radio_contacts);
		mLocalRadio = (RadioButton) findViewById(R.id.main_radio_local);
		mNoticeRadio = (RadioButton) findViewById(R.id.main_radio_notice);
		mSettingRadio = (RadioButton) findViewById(R.id.main_radio_setting);
		mContactsRadio.setOnCheckedChangeListener(this);
		mLocalRadio.setOnCheckedChangeListener(this);
		mNoticeRadio.setOnCheckedChangeListener(this);
		mSettingRadio.setOnCheckedChangeListener(this);
		initSubView(FLAG_CONTACTS);

	}

	
	@Override
	public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
		if (isChecked) {
			switch (buttonView.getId()) {
			case R.id.main_radio_contacts:
				initSubView(FLAG_CONTACTS);
				break;
			case R.id.main_radio_local:
				initSubView(FLAG_LOCAL);
				break;
			case R.id.main_radio_notice:
				initSubView(FLAG_NOTICE);
				break;
			case R.id.main_radio_setting:
				initSubView(FLAG_SETTING);
				break;
			}
		}
	}

	private void initSubView(int flag) {
		// 移除View
		subLayout.removeAllViews();
		Intent intent = null;
		Window subActivity = null;
		switch (flag) {
		case FLAG_CONTACTS:
			intent = new Intent(TabActivityGroup.this,Sub1Activity.class);
			subActivity = getLocalActivityManager().startActivity("Sub1Activity", intent);
			loadView(subActivity, subLayout);
			break;
		case FLAG_LOCAL:
			intent = new Intent(TabActivityGroup.this,Sub2Activity.class);
			subActivity = getLocalActivityManager().startActivity("Sub2Activity", intent);
			loadView(subActivity, subLayout);
			break;

		case FLAG_NOTICE:
			intent = new Intent(TabActivityGroup.this, Sub3Activity.class);
			subActivity = getLocalActivityManager().startActivity("Sub3Activity", intent);
			loadView(subActivity, subLayout);
			break;
			
		case FLAG_SETTING:
			intent = new Intent(TabActivityGroup.this, Sub4Activity.class);
			subActivity = getLocalActivityManager().startActivity("Sub4Activity", intent);
			loadView(subActivity, subLayout);
			break;
		}

	}

	private void loadView(Window subActivity, LinearLayout subLayout) {
		View view = subActivity.getDecorView();
		subLayout.addView(view);
		// 下面的代码是为了保证subactivity显示正常，必须写在这行后面，不然的话，view对象尚未产生，然后。。。你懂的，addView应该也是用InFlate实现的
		LinearLayout.LayoutParams params = (LayoutParams) view.getLayoutParams();
		params.width = LayoutParams.FILL_PARENT;
		params.height = LayoutParams.FILL_PARENT;
		view.setLayoutParams(params);
	}
	
	
	
	
	
	
	
}


